package com.cjj.eatlasflow.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {
    @Value("${spring.data.redis.host}")
    String redisHost;

    @Value("${spring.data.redis.port}")
    String redisPort;

    @Value("${spring.data.redis.database}")
    int database;

    @Value("${spring.datasource.password}")
    String password;

    @Bean
    public RedissonClient redissonClient() {
        // redission客户端配置
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + redisHost + ":" + redisPort)
                .setDatabase(database)
                .setPassword(password);
        // 创建redissionClient对象
        return Redisson.create(config);
    }
}
